<template>
  <div class="main">
    <div class="home">
      <div class="banner">
        <!-- 1. 轮播图组件 -->
        <!-- <banner></banner> -->
        <swiper-banner></swiper-banner>
        <div>
          <div :class="{ bg: isClass }" @click="outInput()"></div>
        </div>
        <!-- 2. 搜索内容 -->
        <el-row class="search">
          <el-col>
            <div>
              <!-- 搜索框 -- 
              1. 聚焦显示热门城市 
              2. 失去焦点，热门城市消失
              3. 输入内容，显示搜索列表 热门城市隐藏
              4. 输入内容 又删除--输入的值为空 搜索列表隐藏 热门城市显示
              5. 输入的值存在 失去焦点，隐藏搜索列表
              6. 输入的值存在，聚焦，显示搜索列表
            -->
              <div class="input-bg">
                <el-input
                  v-model="input"
                  @focus="getInput()"
                  placeholder="请输入内容"
                ></el-input>
              </div>
              <!-- 显示内容区域 -->
              <div class="list-bg" v-show="isShow">
                <div class="list">
                  <p class="info">
                    温馨提示：可以直接输入城市的中文、英文来匹配检索
                  </p>
                  <h3 class="title">热门城市</h3>
                  <div class="hot-citys">
                    <a href="##" v-for="item in hotcity" :key="item.id">{{
                      item.name
                    }}</a>
                  </div>
                </div>
              </div>
              <!-- 显示搜索的列表内容展示 -->
              <div class="search-list" v-show="isShowList">
                <ul class="list">
                  <li v-for="item in searchList" :key="item.id">
                    {{ item.name }}
                    <span>{{ item.en_name }}</span>
                    <span>{{ item.city }}</span>
                  </li>
                </ul>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
      <!-- -----两个图片----------------------------------- -->
      <div class="section">
        <div class="wrapper">
          <div><img src="@/assets/images/left.jpg" width="740px" alt="" /></div>
          <div>
            <img src="@/assets/images/right.jpg" width="400px" alt="" />
          </div>
        </div>
      </div>
      <!-- 今日推荐 -->
      <div class="section-02">
        <div class="title-th">
          <a href="##" class="notice"><span>出境安全提示</span></a>
          今日推荐
        </div>
        <div class="content">
          <el-row :gutter="20">
            <el-col :span="6" v-for="(item, index) in todyInfo" :key="index">
              <div class="item">
                <img :src="item.data.pic" alt="" />
                <div class="info">
                  <div class="subtitle">{{ item.data.subject }}</div>
                  <div class="bottom">
                    <span class="left">{{ item.data.tag}}{{item.data.id}}</span>
                    <span class="right">{{item.data.type}}{{item.data.desc}}{{item.data.start_pos}}</span>
                  </div>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Banner from "./banner/Banner.vue";
import SwiperBanner from "./banner/SwiperBanner.vue";
export default {
  name: "HomeView",
  components: {
    Banner,
    SwiperBanner,
  },
  data() {
    return {
      input: "",
      isClass: false, //是否显示遮罩层
      isShow: false, //是否显示热门城市
      isShowList: false, //是否显示搜索筛选
      hotcity: [], //人们城市的名称
      searchList: [], //搜索列表容器
      todyInfo: [], //今日推荐
    };
  },
  watch: {
    //监听input
    input(val, old) {
      // console.log(val,old)
      //输入值：热门城市--隐藏 搜索列表--展示
      this.isShow = false;
      this.isShowList = true;
      if (!val) {
        this.isShow = true;
        this.isShowList = false;
      }
      //网络请求------------
      this.$api
        .getSearch({
          keyword: val,
        })
        .then((res) => {
          console.log("搜索列表网络请求", res.data);
          this.searchList = res.data.data.list;
          console.log();
        });
    },
  },
  methods: {
    //获取焦点----显示下拉搜索框--
    getInput() {
      if (this.input) {
        this.isShowList = true;
        this.isClass = true;
        return;
      }
      this.isShow = true;
      this.isClass = true;
    },
    //失去焦点---隐藏搜索框--隐藏遮罩--隐藏热门城市
    outInput() {
      this.isShow = false;
      this.isShowList = false;
      this.isClass = false;
    },
    //获取当前城市---------
    async getHotCity() {
      let res = await this.$api.getHotCity();
      this.hotcity = res.data.result.hotcity;
      // console.log(this.hotcity);
    },
    //获取今日推荐-------------
    async getTodyInfo() {
      let res = await this.$api.getTodyInfo();
      this.todyInfo = res.data.data;
      console.log(this.todyInfo);
    },
  },
  created() {
    //1.获取当前热门城市--------
    this.getHotCity();
    //2.获取今日推荐----------
    this.getTodyInfo();
  },
};
</script>

<style lang="less" scoped>
.img {
  width: 100px;
  height: 100px;
}
.bg {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(255, 255, 255, 0.7);
  z-index: 1;
}
.main {
  width: 100%;
  margin: auto;
}
.home {
  width: 100%;
  text-align: center;
}
//搜索框------------------------------
.banner {
  max-width: 1200px;
  margin: auto;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  .search {
    position: absolute;
    width: 600px;
    z-index: 500;
    //输入框
    .input-bg {
      height: 80px;
      background-image: linear-gradient(
        90deg,
        rgba(40, 213, 164, 0.8),
        rgba(38, 208, 181, 0.8)
      );
      display: flex;
      align-items: center;
      padding: 10px;
      border-radius: 5px;
      z-index: 999;
    }
    //热门城市列表
    .list-bg {
      position: absolute;
      top: 65px;
      left: 0%;
      width: 100%;
      height: 100px;
      z-index: 700;
      .list {
        background: #fff;
        border-radius: 4px;
        border: 1px solid #dcdfe6;
        margin: 10px;
        box-sizing: border-box;
        padding: 10px 20px;
        .info {
          font-size: 12px;
          color: #999;
        }
        .title {
          padding-bottom: 10px;
          border-bottom: 1px solid rgb(189, 189, 189);
        }
        .hot-citys {
          a {
            display: inline-block;
            font-size: 14px;
            color: #666;
            padding-right: 10px;
            padding-bottom: 10px;
          }
        }
      }
    }
    //搜索查询列表
    .search-list {
      position: absolute;
      top: 65px;
      left: 0%;
      width: 100%;
      min-height: 60px;
      .list {
        border: 1px solid #dcdfe6;
        border-radius: 4px;
        background-color: #fff;
        box-sizing: border-box;
        margin: 10px;
        padding: 5px 20px;
        li {
          padding: 5px;
        }
      }
    }
  }
}
// 居中容器----------------------------------
.section {
  width: 100%;
  padding: 10px 0px;
  background-color: #eee;
  .wrapper {
    max-width: 1200px;
    margin: auto;
    display: flex;
    overflow: hidden;
    justify-content: space-between;
  }
}
// 两个图片----------------------------------
.el-row {
  width: 100%;
}
//今日推荐---------------------
.section-02 {
  max-width: 1200px;
  margin: auto;
  .title-th {
    text-align: center;
    font-weight: bold;
    font-size: 30px;
    margin: 10px;
    margin-bottom: 20px;
    position: relative;
    .notice {
      background: #02db94;
      border-radius: 20px;
      width: 180px;
      height: 40px;
      line-height: 40px;
      color: #fff;
      font-size: 16px;
      text-align: center;
      display: block;
      position: absolute;
      left: 50px;
      top: 0px;
    }
  }
  .content {
    .item {
      width: 275px;
      height: 300px;
      margin-bottom: 20px;
      img {
        width: 275px;
        height: 185px;
      }
      .info {
        padding: 0 18px;
        border: 1px solid #ececec;
        border-top: 0;
        height: 114px;
        line-height: 24px;
        overflow: hidden;
        text-align: left;
        .subtitle {
          margin-top: 14px;
          height: 48px;
          font-size: 16px;
          overflow: hidden;
        }
        .bottom {
          height: 24px;
          overflow: hidden;
          margin-top: 10px;
          text-overflow: hidden;
          white-space: nowrap;
          color: #636363;
          border: none;
          .left {
            color: #959595;
            font-size: 16px;
            float: right;
          }
          .right {
            display: inline-block;
            max-width: 50%;
            min-width: 30%;
            color: #636363;
            font-size: 14px;
            text-overflow: ellipsis;
            white-space: nowrap;
            overflow: hidden;
          }
        }
      }
    }
  }
}
</style>